+ (Addition Operator)

The Addition Operator is fairly simple to use, and is very common. It has two functions, the first of which is simple addition. If two numbers represent the left and right operands, the numbers are simply added and the result of the addition is returned.



The second function is simple string concatenation, where both the left and right operands are strings. The two strings are joined together, with the left string being the first part of the new string, and the right string being the second part of the new string. If one of the operands is a string and the other a number, the number will be converted to a string, then concatenated.

syntax:

operandOne + operandTwo

EXAMPLE

variableOne = new String("50");

variableTwo = variableOne + 20;

document.write("The contents of variableOne is " + variableOne);

document.write("The contents of variableTwo is " + variableTwo);

The example shows string concatenation, since every one understands simple addition. variableOne has the string "50" loaded into it, and variableTwo is the concatenation of the variableOne value and the number 20. The result of the first document.write statement is 50, while the result of the second documnet.write statement is 5020, the two values, concatenated.